package com.bishe.demo.modules.tourism.dao;

import com.bishe.demo.modules.account.entity.User;
import com.bishe.demo.modules.tourism.entity.RouteEvaluation;
import org.apache.ibatis.annotations.*;
import org.springframework.stereotype.Repository;

import java.util.List;

/**
 * @Description RouteEvaluationDao
 * @Author Lubb
 * @Date 2021/4/1 14:30
 */

@Mapper
@Repository
public interface RouteEvaluationDao {

    @Insert("insert into tourism_evaluation(uid,time,message,star,fk_user_id,fk_route_id) values(#{uid},#{time},#{message},#{star},#{fkUserId},#{fkRouteId})")
    @Options(useGeneratedKeys = true,keyProperty = "id", keyColumn = "id")
    void addRouteEvaluation(RouteEvaluation routeEvaluation);

    @Delete("delete from tourism_evaluation where fk_route_id = routeId")
    void deleteRouteEvaluationByRouteId(Integer routeId);

    @Select("select * from tourism_evaluation where fk_route_id = #{routeId} and uid = 0")
    @Results(id = "baseResult",value = {
            @Result(column = "id",property = "id"),
            @Result(column = "id",property = "comments",javaType = List.class,
            many = @Many(select = "com.bishe.demo.modules.tourism.dao.RouteEvaluationDao.getRouteEvaluationsByUid")),
            @Result(column = "id",property = "user",javaType = User.class,
            many = @Many(select = "com.bishe.demo.modules.account.dao.UserDao.getUserByRouteEvaluationId"))
    })
    List<RouteEvaluation> getRouteEvaluationsByRouteId(Integer routeId);

    @Select("select * from tourism_evaluation where uid = #{uid}")
    @ResultMap("baseResult")
    List<RouteEvaluation> getRouteEvaluationsByUid(Integer uid);
}
